package com.demo.util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;


public class ConnectionUtil {
	public Connection con;
	public PreparedStatement ps;
	public ResultSet rs;
	public void openConnection(){

		
		//连接数据池
		try {
			//获取全局对象
			Context context = new InitialContext();
			//获取数据源对象
			DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/DBTest");
			con = (Connection) ds.getConnection();
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

}
